<?php
/**
 * @author Zeon <scplay@gmail.com>
 * @date 2018/7/26
 * @copyright PanxSoft Inc.
 */
namespace App\Exceptions;

use Illuminate\Contracts\Support\Responsable;

class JsonDebugException extends \Exception implements Responsable
{
    protected $error;
    /**
     * @var bool
     */
    private $log;

    /**
     * ApiException constructor.
     *
     * @param array|string $error
     *
     * @param bool $log
     */
    public function __construct($error, bool $log = false)
    {
        $this->error = $error;
        $this->log = $log;

        parent::__construct('see json data', -1);
    }

    public function report()
    {
        if ($this->log) {
            logger($this->error);
        }
    }

    /**
     * @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
     */
    public function render()
    {
        return response($this->error);
    }

    /**
     * Create an HTTP response that represents the object.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function toResponse($request)
    {
        return $this->render();
    }
}